<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Element Position Example</title>
<script>
function getElementPosition(element) {
    var rect = element.getBoundingClientRect();
    var position = {
        x: rect.left + window.scrollX,
        y: rect.top + window.scrollY
    };
    return position;
}
 
window.onload = function() {
    var childElement = document.getElementById('child');
    var parentElement = document.getElementById('parent');
    var position = getElementPosition(childElement);
    console.log('Child element position:', position);
};
</script>
</head>
<body>
<div id="parent" style="position: relative; height: 500px;">
    <div id="child" style="position: absolute; top: 100px; left: 150px;">
        这是一个子元素
    </div>
</div>
</body>
</html>